import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/assets/icon-font/iconfont.css'
import 'viewerjs/dist/viewer.css'
import VueViewer from 'v-viewer'
import i18n from './i18n'
import { getLang } from '@/api'
import eventBus from '@/composables/useEventBus'
// import VConsole from 'vconsole'
// const vConsole = new VConsole()

const pinia = createPinia()

const initApp = () => {
  const app = createApp(App)
  
  // 设置全局属性
  app.config.globalProperties.$bus = eventBus
  
  // 使用插件
  app.use(pinia)
  app.use(router)
  app.use(ElementPlus)
  app.use(VueViewer)
  app.use(i18n)
  
  // 设置语言
  i18n.global.locale.value = getLang()
  
  app.mount('#app')
  
  return app
}

// 确保 window.$bus 在所有情况下都能访问
window.$bus = eventBus

// 是否处于接管应用模式
// if (window.takeOverApp) {
//   window.initApp = initApp
// } else {
// }

const app = initApp()